package com.shop.shop.controller;


import com.shop.shop.entity.Shopringcart;
import com.shop.shop.service.ShopringcartService;
import com.shop.shop.utile.JWTUtils;
import com.shop.shop.utile.MapUtile;
import com.shop.shop.utile.Q;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.annotation.AccessType;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 * 购物
 *
 * @author 小🌤
 * @since 2021-05-05
 */
@RestController
@RequestMapping("/shop/shopringcart")
public class ShopringcartController {

    @Autowired
    private ShopringcartService shopringcartService;


    /**
     * 保存
     *
     * @param shopringcart
     * @return
     */
    @PostMapping("save")
    public Q save(@RequestBody Shopringcart shopringcart, HttpServletRequest request) {
        Integer userId = JWTUtils.getUserId(request.getHeader("token"));
        shopringcart.setUrId(userId);
        boolean b = shopringcartService.save(shopringcart);
        return b ? Q.ok() : Q.error();
    }

    @GetMapping("list")
    public Q list(MapUtile mapUtile, HttpServletRequest request) {
        Integer userId = JWTUtils.getUserId(request.getHeader("token"));
        Map<String, Object> map = shopringcartService.findPage(mapUtile, userId);
        return Q.ok().data(map);
    }
}

